package com.wxn.entity;
/*
 * Created by wxn
 * 2018/3/21 9:14
 */


public class Page {
	/**
	 * 总条数
	 */
	private int totalNumber;

	/**
	 * 当前第几页
	 */
	private int currentPage;

	/**
	 * 总页数
	 */
	private int totalPage;

	/**
	 * 每页显示条数
	 */
	private int pageNumber = 5;

	/**
	 * 数据库中limit的参数，从第几条开始取
	 */
	private int dbIndex;

	/**
	 * 数据库中limit的参数，一共取多少条
	 */
	private int dbNumber;


//	public static void main(String args[]) {
//		Page page = new Page();
//		page.setTotalNumber(10);
//		page.setPageNumber(3);
//		System.out.println(page.count());
//	}


	/**
	 * 根据当前对象属性值计算并设置相关属性值
	 */
	public void count() {
		//计算总页数
		this.totalPage = (int) Math.ceil((double) totalNumber / (double) pageNumber);

		//设置当前页数
		//总页数小于当前页数，把当前页数设为总页数
		if (totalPage < currentPage) {
			currentPage = totalPage;
		}
		//当前页数小于1 ，把当前页数设为1
		if (currentPage < 1) {
			currentPage = 1;
		}

		//设置limit参数
		dbIndex = (currentPage - 1) * pageNumber;
		dbNumber = pageNumber;
	}

	public int getTotalNumber() {
		return totalNumber;
	}

	public void setTotalNumber(int totalNumber) {
		this.totalNumber = totalNumber;
		count();
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	public int getDbIndex() {
		return dbIndex;
	}

	public void setDbIndex(int dbIndex) {
		this.dbIndex = dbIndex;
	}

	public int getDbNumber() {
		return dbNumber;
	}

	public void setDbNumber(int dbNumber) {
		this.dbNumber = dbNumber;
	}
}
